﻿
@{
    ViewData["Title"] = "Role";
    Layout = "~/Views/Home/Main.cshtml";
}

<!DOCTYPE html>
<html>
<head>

</head>
<body>
    <h1>角色添加</h1>
    <form class="layui-form layui-form-pane" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">角色名称:</label>
            <div class="layui-input-inline layui-input-wrap">
                <input type="text" id="name" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">角色类别</label>
                <div class="layui-input-inline layui-input-wrap">
                    <input type="text" id="role_type" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">数据范围:</label>
            <div class="layui-input-block">
                <input type="radio" name="data_scope" value="1" class="layui-input" />全部数据
                <input type="radio" name="data_scope" value="2" class="layui-input" />公司已下数据
                <input type="radio" name="data_scope" value="8" checked class="layui-input" />个人数据
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label"> 状态:</label>
                <div class="layui-input-block">
                    <input type="radio" name="useable" value="0" class="layui-input" />禁用
                    <input type="radio" name="useable" value="1" class="layui-input" />启用
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <input type="button" class="layui-btn layui-btn-primary layui-border" value="添加" onclick="RoleAdd()" />
        </div>
    </form>
    @* <script src="//unpkg.com/layui@2.9.18/dist/layui.js"></script> *@
    <script>
        layui.use(function () {
            var form = layui.form;
            var layer = layui.layer;
            // 提交事件
        });
        function RoleAdd() {
            name = $("#name").val();
            role_type = $("#role_type").val();
            var model = JSON.stringify({
                name: name,
                role_type: role_type,
                useable: $("[name=useable]:checked").val(),
                data_scope: $("[name=data_scope]:checked").val(),
                role_level: 0
            })
            console.log(model)
            var token = localStorage.getItem("token")
            $.ajax({
                url: '../User/RoleDo',
                type:'post',
                data:{model:model, token: token},
                //contentType: 'application/json',
                success: function (res) {
                    console.log(res)
                    var res = JSON.parse(res)
                    if (res.code == 200) {

                        alert("添加成功")
                    }
                    else {
                        alert("添加失败")
                    }
                }
            })
        }
    </script>

</body>
</html>
